#pragma once

#include"noncopyable.h"
#include<memory>
#include<unistd.h>
#include<string>
#include<functional>
#include<thread>
#include<atomic>

class Thread : noncopyable
{
public:
    // 使用绑定器和函数对象就可以传参了。
    using ThreadFunc = std::function<void()>;

    Thread(ThreadFunc func,const std::string& name= std::string());
    ~Thread();

    void start();
    void join();

    bool started() const{return started_;}

    pid_t tid() const {return tid_;}
    const std::string& name() const{return name_;}

    static int numCreated() {return numCreated_;}
private:
    void setDefaultName();
    bool started_;
    bool joined_;  
    std::shared_ptr<std::thread> thread_; // 这里的thread是线程里面的thread
    pid_t tid_;
    ThreadFunc func_;
    std::string name_; // 线程名
    static std::atomic_int numCreated_;
};